package com.example.pungolo.journal.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DiaryPage {
  int day;
  String imagePath;
  final int[] crop = new int[4];
  final List<DiaryEntry> entries = new ArrayList<DiaryEntry>();
  
  public Date getDate() {
    return DateUtils.dateFromDay(day);
  }
  
  public String getImagePath() {
    return imagePath;
  }
  
  public int getEntryCount() {
    return entries.size();
  }
  
  public DiaryEntry getEntry(int index) {
    return entries.get(index);
  }
  
  public DiaryEntry getDiaryEntryByDate(Date date) {
    int c = getEntryCount();
    for (int i = 0; i < c; i++)
      if (getEntry(i).getDate().equals(date))
        return getEntry(i);
    return null;
  }
  
  public int[] getCropData() {
    return crop;
  }
  
  public void setDate(Date day) {
    this.day = DateUtils.dayFromDate(day);
  }
  
  public void setImagePath(String image) {
    this.imagePath = image;
  }
  
  public void setCropData(int[] cropData) {
    if (cropData.length != 4) throw new IllegalArgumentException();
    for (int i = 0; i < 4; i++) {
      crop[i] = cropData[i];
    }
  }
  
  public void addEntry(DiaryEntry entry) {
    entries.add(entry);
  }
  
  public void save() {
	DiaryIO.getDatabase().saveDiaryPage(this);
  }
}
